home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0022_SWAPNUMS.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  499b  |  30 lines

  1. {
  2. >Is there a way (using bit manipulations such as AND, OR, XOR) to
  3. >swap to Variables without making a 3rd temporary Variable?
  4. >
  5.  
  6. If the two Variables are numbers, and the following operations
  7. won't overflow the limitations of the Type, then yes, you can
  8. do it like this:
  9. }
  10. Var
  11.    A, B : Integer;
  12.  
  13. begin
  14.    A := 5;
  15.    B := 3;
  16.  
  17.    A := A + B;
  18.    B := A - B;
  19.    A := A - B;
  20.  
  21.    { which is
  22.  
  23.    A := 5 + 3 (8)
  24.    B := 8 - 3 (5)
  25.    A := 8 - 5 (3)
  26.  
  27.    A = 3
  28.    B = 5 }
  29.  
  30. end;